package com.chen.blue.controller.admin.system;


import com.chen.blue.annotation.permission.DataPermission;
import com.chen.blue.domain.delete.system.DeptDelete;
import com.chen.blue.domain.dto.system.DeptDto;
import com.chen.blue.domain.dto.system.update.DeptDtoEdit;
import com.chen.blue.domain.query.system.DeptQuery;
import com.chen.blue.domain.vo.system.DeptVo;
import com.chen.blue.exception.e.DtoNullException;
import com.chen.blue.result.DataResult;
import com.chen.blue.result.R;
import com.chen.blue.service.system.IDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author CLT
 * @since 2024-04-29
 */
@Api(tags = "部门模块")
@Validated
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Resource
    private IDeptService iDeptService;

    @ApiOperation(value = "部门添加", notes = "部门添加")
    @PostMapping("/add")
    public R add(@RequestBody @Valid DeptDto deptDto) throws DtoNullException {

        return iDeptService.addDept(deptDto) ? R.success() : R.faild();

    }

    @ApiOperation(value = "部门删除", notes = "部门删除")
    @DeleteMapping("/delete")
    public R delete(@RequestBody DeptDelete deptDelete) throws DtoNullException {

        return iDeptService.deleteDept(deptDelete) ? R.success() : R.faild();

    }

    @ApiOperation(value = "部门修改", notes = "部门修改")
    @PutMapping("/edit")
    public R updateById(@RequestBody @Valid DeptDtoEdit deptDtoEdit) throws DtoNullException {

        return iDeptService.updateDeptById(deptDtoEdit) ? R.success() : R.faild();

    }

    @DataPermission
    @ApiOperation(value = "多条件查询部门(已配数据权限)", notes = "多条件查询部门(已配数据权限)")
    @PostMapping("/query")
    public R<DataResult<List<DeptVo>>> query(@RequestBody DeptQuery deptQuery) throws DtoNullException {

        return R.success(iDeptService.queryDept(deptQuery, false));

    }

    @ApiOperation(value = "ID查询部门", notes = "ID查询部门")
    @GetMapping("/queryById/{id}")
    public R<DataResult<List<DeptVo>>> queryById(@PathVariable("id") Long id) throws DtoNullException {

        return R.success(iDeptService.queryDeptById(id));

    }

}

